﻿using SMARTMobile.Models.Local;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace SMARTMobile.ViewModels
{
    public partial class NoTelerikMainViewModel
    {
        private readonly List<ButtonInfo> _menuButtonInfoList = new List<ButtonInfo>();

        private Grid _buttonGrid;
        private StackPanel _menuBar;
        
        private string _onProcess = string.Empty;

        #region Menu Properties

        public List<SqlGroup> GroupList { get; private set; }

        public List<SqlGroupGroup> GroupGroupList { get; private set; }

        public List<SqlGroupMenu> GroupMenuList { get; set; }

        public List<SqlMenu> MenuList { get; private set; }

        public List<SqlObject> ObjectList { get; private set; }

        public List<SqlObjectMenu> ObjectMenuList { get; private set; }

        public List<SqlObjectGroup> ObjectGroupList { get; private set; }

        #endregion

        /// <summary>
        /// Loads all menu data from scratch.
        /// </summary>
        partial void LoadMenuData()
        {
            this.LoadGroup();
            this.LoadGroupGroup();
            this.LoadGroupMenu();
            this.LoadMenuList();
            this.LoadObjectList();
            this.LoadObjectMenuList();
            this.LoadObjectGroupList();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userType">DSR or SS</param>
        /// <param name="appStatus"></param>
        partial void PopulateActionButtonPanel(string userType, string appStatus)
        {
            // Gets button infos Quy Trinh, Tac Vu...
            List<SqlObject> actionButtonList = this.ObjectList.Where(o => o.UseType == userType && o.AppStatus.ToString() == appStatus).ToList();

            this.AddActionButtons(actionButtonList);

            // Updates app status to get menu
            this.RegisteredUser.AppStatus = "1";

            // Gets group ID
            ////List<SqlObjectGroup> groupIDList = this.ObjectGroupList.Where(og=>og.Objectid)
        }

        #region Command Action Handlers

        private void OnContentPanelLoaded(object commandParams)
        {
            this._buttonGrid = commandParams as Grid;

            this.PopulateActionButtonPanel(this.RegisteredUser.UserType, this.RegisteredUser.AppStatus);
        }

        private void OnMenubarLoaded(object commandParams)
        {
            this._menuBar = commandParams as StackPanel;
        }

        #endregion

        #region Button and Menu Data Loaders

        private void LoadGroup()
        {
            this.GroupList = new List<SqlGroup>
			{
				new SqlGroup { Groupkey = "CBDN", Groupdes = "Chuẩn bị đầu ngày", Image = "saleorder.png", isEdite = null, UseType = "DSR", AppStatus = 1, Sort = 0 },
				new SqlGroup { Groupkey = "BHTT", Groupdes = "Bán hàng trên tuyến", Image = "presale.png", isEdite = null, UseType = "DSR", AppStatus = 1, Sort = 1 },
				new SqlGroup { Groupkey = "KTN", Groupdes = "Kết thúc ngày", Image = "report.png", isEdite = null, UseType = "DSR", AppStatus = 1, Sort = 2 },
				new SqlGroup { Groupkey = "QLT", Groupdes = "Quản lý tuyến", Image = "maps.png", isEdite = null, UseType = "DSR", AppStatus = 1, Sort = 1 },
				new SqlGroup { ﻿Groupkey = "SYS", Groupdes = "Quản lý hệ thống", Image = "configuration.png", isEdite = null, UseType = "DSR", AppStatus = 1, Sort = 1 },
				new SqlGroup { Groupkey = "BC", Groupdes = "Báo cáo tổng hợp", Image = "sumsale.png", isEdite = null, UseType = "DSR", AppStatus = 1, Sort = 1 },
				new SqlGroup { Groupkey = "XNT", Groupdes = "Xuất nhập tồn", Image = "saleorder.png", isEdite = null, UseType = "DSR", AppStatus = 1, Sort = 1 },
				new SqlGroup { ﻿Groupkey = "LT", Groupdes = "Trên Tuyến", Image = "changeroute.png", isEdite = null, UseType = "DSR", AppStatus = 2, Sort = 1 },
				new SqlGroup { ﻿Groupkey = "LTCBDN", Groupdes = "Chuẩn bị đầu ngày", Image = "saleorder.png", isEdite = null, UseType = "DSR", AppStatus = 2, Sort = 0 },
				new SqlGroup { ﻿Groupkey = "LTKTN", Groupdes = "Kết thúc ngày", Image = "report.png", isEdite = null, UseType = "DSR", AppStatus = 2, Sort = 2 },
				new SqlGroup { ﻿Groupkey = "QTBH", Groupdes = "Qui trình bán hàng", Image = "saleorder.png", isEdite = null, UseType = "DSR", AppStatus = 1, Sort = 1 },
				new SqlGroup { ﻿Groupkey = "QTLT", Groupdes = "Qui trình làm tuyến", Image = "saleorder.png", isEdite = null, UseType = "DSR", AppStatus = 2, Sort = 2 },
				new SqlGroup { ﻿Groupkey = "SSLTCBDN", Groupdes = "Chuẩn bị đầu ngày", Image = "changeroute.png", isEdite = null, UseType = "SS", AppStatus = 2, Sort = 0 },
				new SqlGroup { ﻿Groupkey = "SSQTLT", Groupdes = "Qui trình làm tuyến", Image = "changeroute.png", isEdite = null, UseType = "SS", AppStatus = 2, Sort = 2 },
				new SqlGroup { ﻿Groupkey = "SSLTKTN", Groupdes = "Kết thúc ngày", Image = "report.png", isEdite = null, UseType = "SS", AppStatus = 2, Sort = 2 },
				new SqlGroup { ﻿Groupkey = "SSLTTT", Groupdes = "Trên Tuyến", Image = "changeroute.png", isEdite = null, UseType = "SS", AppStatus = 2, Sort = 1 },
				new SqlGroup { ﻿Groupkey = "SSQTBH", Groupdes = "Qui trình bán hàng", Image = "saleorder.png", isEdite = null, UseType = "SS", AppStatus = 1, Sort = 1 },
				new SqlGroup { Groupkey = "SSBHCBDN", Groupdes = "Chuẩn bị đầu ngày", Image = "saleorder.png", isEdite = null, UseType = "SS", AppStatus = 1, Sort = 0 },
				new SqlGroup { ﻿Groupkey = "SSBHKTN", Groupdes = "Kết thúc ngày", Image = "report.png", isEdite = null, UseType = "SS", AppStatus = 1, Sort = 2 },
				new SqlGroup { ﻿Groupkey = "SSBHTT", Groupdes = "Trên Tuyến", Image = "listcustomer.png", isEdite = null, UseType = "SS", AppStatus = 2, Sort = 1 },
				new SqlGroup { ﻿Groupkey = "DHLNCC", Groupdes = "Đặt hàng lên nhà cung cấp", Image = "report.png", isEdite = null, UseType = "SS", AppStatus = 0, Sort = 2 }
			};
        }

        private void LoadGroupGroup()
        {
            this.GroupGroupList = new List<SqlGroupGroup>
			{
				new SqlGroupGroup { PrGroup="QTLT", ChGroup = "LTCBDN" },
				new SqlGroupGroup { PrGroup="QTLT", ChGroup = "LTKTN" },
				new SqlGroupGroup { PrGroup="QTLT", ChGroup = "LT" },
				new SqlGroupGroup { PrGroup="QTBH", ChGroup = "CBDN" },
				new SqlGroupGroup { PrGroup="QTBH", ChGroup = "KTN" },
				new SqlGroupGroup { PrGroup="QTBH", ChGroup = "BHTT" },
				new SqlGroupGroup { PrGroup="SSQTLT", ChGroup = "SSLTCBDN" },
				new SqlGroupGroup { PrGroup="SSQTLT", ChGroup = "SSLTKTN" },
				new SqlGroupGroup { PrGroup="SSQTLT", ChGroup = "SSLTTT" },
				new SqlGroupGroup { PrGroup="SSQTBH", ChGroup = "SSBHCBDN" },
				new SqlGroupGroup { PrGroup="SSQTBH", ChGroup = "SSBHKTN" },
				new SqlGroupGroup { PrGroup="SSQTBH", ChGroup = "SSBHTT" },
			};
        }

        private void LoadGroupMenu()
        {
            this.GroupMenuList = new List<SqlGroupMenu>
			{
				new SqlGroupMenu { Groupid = "1", Menuid = "1",	NextProcess = string.Empty,	GroupKey = "CBDN", MenuKey = "DSRDBDL", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6",	NextProcess = "BHCHKH",	GroupKey = "BHTT", MenuKey = "DSRGT", isEnd = 0, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "23", NextProcess = "CILOC",	GroupKey = "BHTT", MenuKey = "SUMARY", isEnd = 0, Sort = 3, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "35", NextProcess = "ORDER",	GroupKey = "BHTT", MenuKey = "IMAGE", isEnd = 0, Sort = 5, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "35", NextProcess = "IMAGE",	GroupKey = "BHTT", MenuKey = "CILOC", isEnd = 0, Sort = 4, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "LTCHKH",	GroupKey = "LT", MenuKey = "DSRGT", isEnd = 0, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "37", NextProcess = "REP",	GroupKey = "BHTT", MenuKey = "ORDER", isEnd = 0, Sort = 6, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "38", NextProcess = "0", GroupKey = "BHTT", MenuKey = "REP", isEnd = 1, Sort = 7, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "LT", MenuKey = "CMR", isEnd = 1, Sort = 4, Show = 0 },
				new SqlGroupMenu { Groupid = "3", Menuid = "1", NextProcess = "0", GroupKey = "KTN", MenuKey = "DSRDBDL", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "4", Menuid = "2", NextProcess = "0", GroupKey = "XNT", MenuKey = "DH", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "4", Menuid = "25", NextProcess = "0", GroupKey = "XNT", MenuKey = "DHPRE", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "5", Menuid = "5", NextProcess = "0", GroupKey = "QLT", MenuKey = "DGPS", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "5", Menuid = "4", NextProcess = "0", GroupKey = "QLT", MenuKey = "TKHM", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "6", Menuid = "23", NextProcess = "0", GroupKey = "GPS", MenuKey = "MAP", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "6", Menuid = "32", NextProcess = "0", GroupKey = "GPS", MenuKey = "MYLOCA", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "6", Menuid = "27", NextProcess = "0", GroupKey = "GPS", MenuKey = "CHAMCONG", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "7", Menuid = "8", NextProcess = "0", GroupKey = "BC", MenuKey = "BCNGAY", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "8", Menuid = "19", NextProcess = "0", GroupKey = "SYS", MenuKey = "ST", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "1", Menuid = "39", NextProcess = "0", GroupKey = "CBDN", MenuKey = "CBDN", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "3", Menuid = "40", NextProcess = "0", GroupKey = "KTN", MenuKey = "TKBHCN", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "1", Menuid = "41", NextProcess = "0", GroupKey = "CBDN", MenuKey = "DNMTD", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "8", Menuid = "26", NextProcess = "0", GroupKey = "BC", MenuKey = "TTDLBH", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "SUMARY", GroupKey = "BHTT", MenuKey = "BHCHKH", isEnd = 0, Sort = 2, Show = 1 },
				new SqlGroupMenu { Groupid = "3", Menuid = "23", NextProcess = "0", GroupKey = "LTKTN", MenuKey = "MAP", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "1", Menuid = "1", NextProcess = "0", GroupKey = "LTCBDN", MenuKey = "DSRDBDL", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "3", Menuid = "1", NextProcess = "0", GroupKey = "LTKTN", MenuKey = "DSRDBDL", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSLTTT", MenuKey = "SSMAPCHR", isEnd = 1, Sort = 2, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSLTCBDN", MenuKey = "SSDBDL", isEnd = 1, Sort = 2, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSLTKTN", MenuKey = "SSDBDL", isEnd = 1, Sort = 2, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHCBDN", MenuKey = "SSDBDL", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "DHLNCC", MenuKey = "DHLNCC", isEnd = 1, Sort = 2, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSLTTT", MenuKey = "PTBH", isEnd = 1, Sort = 2, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "CMR", GroupKey = "LT", MenuKey = "CNTTKH", isEnd = 0, Sort = 3, Show = 0 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "CNTTKH", GroupKey = "LT", MenuKey = "LTCHKH", isEnd = 0, Sort = 2, Show = 0 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHKTN", MenuKey = "SSDBDL", isEnd = 1, Sort = 2, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHCBDN", MenuKey = "LKHGT", isEnd = 1, Sort = 1, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHTT", MenuKey = "LKHGT", isEnd = 1, Sort = 2, Show = 1 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHTT", MenuKey = "SSGT", isEnd = 1, Sort = 1, Show = 0 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHTT", MenuKey = "DKHM", isEnd = 1, Sort = 2, Show = 0 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHTT", MenuKey = "DDVT", isEnd = 1, Sort = 1, Show = 0 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHTT", MenuKey = "PTBH", isEnd = 1, Sort = 2, Show = 0 },
				new SqlGroupMenu { Groupid = "2", Menuid = "6", NextProcess = "0", GroupKey = "SSBHTT", MenuKey = "TTBH", isEnd = 1, Sort = 1, Show = 0 },
			};
        }

        /// <summary>
        /// Loads the action buttons on main panel.
        /// </summary>
        private void LoadObjectList()
        {
            this.ObjectList = new List<SqlObject>
			{
				new SqlObject { ﻿ID = "QT", Description = "Qui trình", Image = "usertype.png", UseType = "DSR", ObjectType = 1, AppStatus = 0 },
				new SqlObject { ﻿ID = "KH", Description = "Khách hàng", Image = "listcustomer.png", UseType = "DSR", ObjectType = 0, AppStatus = 0 },
				new SqlObject { ﻿ID = "TV", Description = "Tác vụ", Image = "duyetkhmoi.png", UseType = "DSR", ObjectType = 0, AppStatus = 0 },
				new SqlObject { ﻿ID = "BC", Description = "Báo cáo", Image = "report.png", UseType = "DSR", ObjectType = 0, AppStatus = 1 },
				new SqlObject { ﻿ID = "NV", Description = "Nhân viên", Image = "listcustomer.png", UseType = "DSR", ObjectType = 0, AppStatus = 1 },
				new SqlObject { ﻿ID = "SSKH", Description = "Khách hàng", Image = "listcustomer.png", UseType = "SSS", ObjectType = 0, AppStatus = 1 },
				new SqlObject { ﻿ID = "SSBC", Description = "Báo cáo", Image = "report.png", UseType = "SS", ObjectType = 0, AppStatus = 1 },
				new SqlObject { ID = "SSHT", Description = "Tác vụ", Image = "duyetkhmoi.png", UseType = "SS", ObjectType = 0, AppStatus = 0 },
				new SqlObject { ID = "SSQT", Description = "Qui trình", Image = "usertype.png", UseType = "SS", ObjectType = 1, AppStatus = 0 }
			};
        }

        private void LoadMenuList()
        {
            this.MenuList = new List<SqlMenu>
            {
                new SqlMenu { ID = 24, Type = "KQDH", Description = "Kết quả giao hàng", imge = "ketquagiaohang.png", loction = 0, usertype = "rsu", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 6, Type = "DSRGT", Description = "Ghé thăm", imge = "visit.png", loction = 2, usertype = "DSR", inmagevalues = 2130837524, AppStatus = 0 },
                new SqlMenu { ID = 2, Type = "DH", Description = "Đơn hàng Trực tiếp", imge = "saleorder.png", loction = 0, usertype = "DSR", inmagevalues = 2130837518, AppStatus = 1 },
                new SqlMenu { ID = 3, Type = "BC", Description = "Báo cáo", imge = "report.png", loction = 0, usertype = "DSR", inmagevalues = 2130837517, AppStatus = 1 },
                new SqlMenu { ID = 4, Type = "TKHM", Description = "Nhập thông tin khách hàng", imge = "add.png", loction = 0, usertype = "DSR", inmagevalues = 2130837504, AppStatus = 0 },
                new SqlMenu { ID = 5, Type = "DGPS", Description = "Đổi thông tin khách hàng", imge = "changgps.png", loction = 0, usertype = "DSR", inmagevalues = 2130837506, AppStatus = 1 },
                new SqlMenu { ID = 1, Type = "DSRDBDL", Description = "Đồng bộ dữ liệu", imge = "reload.png", loction = 2, usertype = "DSR", inmagevalues = 2130837516, AppStatus = 0 },
                new SqlMenu { ID = 7, Type = "XTNH", Description = "Xem tin nhắn", imge = "recicesms.png", loction = 1, usertype = "DSR", inmagevalues = 2130837515, AppStatus = 1 },
                new SqlMenu { ID = 8, Type = "BCNGAY", Description = "Doanh số", imge = "sumsale.png", loction = 0, usertype = "DSR", inmagevalues = 2130837521, AppStatus = 1 },
                new SqlMenu { ID = 9, Type = "LKHGT", Description = "Kế hoạch ghé thăm", imge = "calendar.png", loction = 0, usertype = "SS", inmagevalues = 2130837505, AppStatus = 1 },
                new SqlMenu { ID = 10, Type = "NHT", Description = "Nhắn tin", imge = "sendsms.png", loction = 0, usertype = "SS", inmagevalues = 2130837519, AppStatus = 1 },
                new SqlMenu { ID = 11, Type = "SSGT", Description = "Ghé thăm", imge = "visit.png", loction = 0, usertype = "SS", inmagevalues = 2130837524, AppStatus = 1 },
                new SqlMenu { ID = 12, Type = "DKHM", Description = "Duyệt khách hàng mới", imge = "duyetkhmoi.png", loction = 2, usertype = "SS", inmagevalues = 2130837511, AppStatus = 1 },
                new SqlMenu { ID = 13, Type = "DDVT", Description = "Duyệt Đổi vị trí khách hàng", imge = "duyetdoigps.png", loction = 2, usertype = "SS", inmagevalues = 2130837510, AppStatus = 1 },
                new SqlMenu { ID = 15, Type = "GH", Description = "Giao hàng", imge = "delivery.png", loction = 0, usertype = "rsu", inmagevalues = 2130837508, AppStatus = 1 },
                new SqlMenu { ID = 16, Type = "THCN", Description = "Thu hồi công nợ", imge = "thuhoicongno.png", loction = 0, usertype = "rsu", inmagevalues = 2130837522, AppStatus = 1 },
                new SqlMenu { ID = 17, Type = "GNDBDL", Description = "Đồng bộ dữ liệu", imge = "reload.png", loction = 2, usertype = "rsu", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 17, Type = "SSDBDL", Description = "Đồng bộ dữ liệu", imge = "reload.png", loction = 0, usertype = "SS", inmagevalues = 2130837516, AppStatus = 0 },
                new SqlMenu { ID = 17, Type = "ST", Description = "Đăng ký thông tin", imge = "configuration.png", loction = 0, usertype = "ad", inmagevalues = 2130837516, AppStatus = 0 },
                new SqlMenu { ID = 17, Type = "NH", Description = "Nhận Hàng", imge = "moveinloc.png", loction = 0, usertype = "DSR", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 14, Type = "KQKDDSR", Description = "Cập nhật kết quả kinh doanh của nhân viên", imge = "stockmarket.png", loction = 1, usertype = "SS", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 21, Type = "KQKD", Description = "Tóm tắt bán hàng", imge = "sumsale.png", loction = 1, usertype = "DSR", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 22, Type = "DNH", Description = "Duyệt nhận hàng", imge = "moveinloc.png", loction = 0, usertype = "SS", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 25, Type = "DHPRE", Description = "Đơn hàng giao sau", imge = "presale.png", loction = 0, usertype = "DSR", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 25, Type = "MAP", Description = "Bản đồ", imge = "maps.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 0 },
                new SqlMenu { ID = 26, Type = "TTDLBH", Description = "Tra cứu thông tin", imge = "ketquagiaohang.png", loction = 0, usertype = "DSR", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 27, Type = "CHAMCONG", Description = "Chấm công", imge = "ketquagiaohang.png", loction = 0, usertype = "DSR", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 28, Type = "END", Description = "Kết thúc ghé thăm", imge = "ketquagiaohang.png", loction = 0, usertype = "DSR", inmagevalues = 2130837516, AppStatus = 1 },
                new SqlMenu { ID = 29, Type = "SSMAP", Description = "Bản đồ", imge = "maps.png", loction = 0, usertype = "SS", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 30, Type = "PTBH", Description = "Phân tuyến bán hàng", imge = "changgps.png", loction = 0, usertype = "SS", inmagevalues = 2130837520, AppStatus = 0 },
                new SqlMenu { ID = 31, Type = "TTBH", Description = "Thứ tự bao trùm", imge = "changgps.png", loction = 0, usertype = "SS", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 32, Type = "MYLOCA", Description = "Vị trí của tôi", imge = "changgps.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 33, Type = "SUMARY", Description = "Xem tổng quan", imge = "sumsale.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 34, Type = "IMAGE", Description = "Chụp hình", imge = "camera.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 35, Type = "CILOC", Description = "Kiểm tồn", imge = "report.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 36, Type = "PRV", Description = "Giới thiệu Chương trình Khuyến mãi", imge = "thuhoicongno.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 37, Type = "ORDER", Description = "Lấy Đơn hàng", imge = "saleorder.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 38, Type = "REP", Description = "Báo cáo tại điểm bán", imge = "report.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 39, Type = "CBDN", Description = "Xem Chỉ tiêu đầu ngày", imge = "report.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 40, Type = "TKBHCN", Description = "Tổng kết cuối ngày", imge = "report.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 41, Type = "DNMTD", Description = "Tổng hợp trong tháng", imge = "report.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 42, Type = "KHDGT", Description = "Đã ghé thăm", imge = "visit.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 0 },
                new SqlMenu { ID = 43, Type = "LORDER", Description = "Đơn hàng", imge = "saleorder.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 44, Type = "ABSW", Description = "Thông tin về hệ thống", imge = "report.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 1 },
                new SqlMenu { ID = 45, Type = "CMR", Description = "Chụp hình", imge = "camera.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 2 },
                new SqlMenu { ID = 29, Type = "SSMAPCHR", Description = "Duyệt thông tin làm tuyến", imge = "maps.png", loction = 0, usertype = "SS", inmagevalues = 2130837520, AppStatus = 2 },
                new SqlMenu { ID = 45, Type = "DHLNCC", Description = "Đặt hàng", imge = "saleorder.png", loction = 0, usertype = "SS", inmagevalues = 2130837520, AppStatus = 0 },
                new SqlMenu { ID = 46, Type = "PIS", Description = "Yêu cầu hỗ trợ", imge = "configuration.png", loction = 0, usertype = "SS", inmagevalues = 2130837520, AppStatus = 0 },
                new SqlMenu { ID = 48, Type = "LTCHKH", Description = "Chọn khách hàng", imge = "add.png", loction = 0, usertype = "DSR", inmagevalues = 2130837504, AppStatus = 0 },
                new SqlMenu { ID = 48, Type = "BHCHKH", Description = "Chọn khách hàng", imge = "add.png", loction = 0, usertype = "DSR", inmagevalues = 2130837504, AppStatus = 0 },
                new SqlMenu { ID = 47, Type = "CNTTKH", Description = "Thông tin khách hàng", imge = "add.png", loction = 0, usertype = "DSR", inmagevalues = 2130837504, AppStatus = 0 },
                new SqlMenu { ID = 46, Type = "DSRPIS", Description = "Yêu cầu hổ trợ", imge = "configuration.png", loction = 0, usertype = "DSR", inmagevalues = 2130837520, AppStatus = 0 },
                new SqlMenu { ID = 46, Type = "VIS", Description = "Xem yêu cầu hỗ trợ", imge = "configuration.png", loction = 0, usertype = "SS", inmagevalues = 2130837520, AppStatus = 0 },
            };
        }

        private void LoadObjectMenuList()
        {
            this.ObjectMenuList = new List<SqlObjectMenu>
            {
                new SqlObjectMenu { Objectid = "KH", Menuid = "LORDER", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "KH", Menuid = "KHDGT", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "NV", Menuid = "CHAMCONG", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "NV", Menuid = "MYLOCA", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "KH", Menuid = "TKHM", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "KH", Menuid = "DH", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "TV", Menuid = "ABSW", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSBC", Menuid = "SSMAP", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSQT", Menuid = "PIS", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSHT", Menuid = "NHT", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "QT", Menuid = "DSRPIS", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSQT", Menuid = "VIS", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSKH", Menuid = "DDVT", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSBC", Menuid = "KQKDDSR", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSKH", Menuid = "PTBH", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSKH", Menuid = "TTBH", isEnd = "1", NextProcess = "0" },
                new SqlObjectMenu { Objectid = "SSHT", Menuid = "ST", isEnd = "1", NextProcess = "0" },
            };
        }

        private void LoadObjectGroupList()
        {
            this.ObjectGroupList = new List<SqlObjectGroup>
            {
                new SqlObjectGroup { Objectid = "SSQT", GroupId = "SSQTLT" },
                new SqlObjectGroup { Objectid = "QT", GroupId = "QTBH" },
                new SqlObjectGroup { Objectid = "QT", GroupId = "QTLT" },
                new SqlObjectGroup { Objectid = "TV", GroupId = "GPS" },
                new SqlObjectGroup { Objectid = "TV", GroupId = "QLT" },
                new SqlObjectGroup { Objectid = "TV", GroupId = "SYS" },
                new SqlObjectGroup { Objectid = "TV", GroupId = "BC" },
                new SqlObjectGroup { Objectid = "TV", GroupId = "XNT" },
                new SqlObjectGroup { Objectid = "BC", GroupId = "BC" },
                new SqlObjectGroup { Objectid = "QTBH", GroupId = "CBDN" },
                new SqlObjectGroup { Objectid = "QTBH", GroupId = "BHTT" },
                new SqlObjectGroup { Objectid = "QTBH", GroupId = "KTN" },
                new SqlObjectGroup { Objectid = "QTLT", GroupId = "LT" },
                new SqlObjectGroup { Objectid = "QTLT", GroupId = "LTCBDN" },
                new SqlObjectGroup { Objectid = "QTLT", GroupId = "LTKTN" },
                new SqlObjectGroup { Objectid = "SSQT", GroupId = "SSQTBH" },
                new SqlObjectGroup { Objectid = "SSQT", GroupId = "DHLNCC" },
            };
        }

        #endregion

        private void AddActionButtons(List<SqlObject> actionButtonList)
        {
            this._buttonGrid.Children.Clear();
            this._buttonGrid.ColumnDefinitions.Clear();

            int i = 0;
            ColumnDefinition column = null;
            Button actionButton = null;

            //../Images/Process.png

            foreach (SqlObject action in actionButtonList)
            {
                column = new ColumnDefinition();
                column.Width = new GridLength(int.MaxValue, GridUnitType.Star);

                this._buttonGrid.ColumnDefinitions.Add(column);

                ButtonInfo actionButtonInfo = new ButtonInfo
                {
                    Key = action.ID,
                    Text = action.Description,
                    Image = this.GetButtonIconUrl(action.Description)
                };

                actionButton = this.CreateButton(actionButtonInfo);

                Grid.SetColumn(actionButton, i);

                this._buttonGrid.Children.Add(actionButton);

                ++i;
            }
        }

        private string GetButtonIconUrl(string buttonName)
        {
            string buttonIconUrl = string.Empty;

            switch(buttonName)
            {
                case "Quy trình":
                    buttonIconUrl = @"../Images/Process.png";
                    break;
                case "Khách hàng":
                    buttonIconUrl = @"../Images/Patient.png";
                    break;
                case "Tác vụ":
                    buttonIconUrl = @"../Images/Setting.png";
                    break;
                case "Báo cáo":
                    // TODO: add report image
                    buttonIconUrl = @"../Images/Setting.png";
                    break;
                default:
                    buttonIconUrl = @"../Images/Setting.png";
                    break;
            }

            return buttonIconUrl;
        }
        
        

        private void ActionButtonOnClick(object sender, RoutedEventArgs e)
        {
            // resets menu-bar
            this._menuBar.Children.Clear();

            Button actionButton = sender as Button;

            string objectTag = actionButton.Tag.ToString();

            int fakeAppStatus = -1;
            

            this.OnSidebarStateChanged(true);
        }

        private void SidebarMenuOnClick(object sender, RoutedEventArgs e)
        {
            this.OnSidebarStateChanged(true);

            Button clicked = sender as Button;
            string itemID = clicked.Tag.ToString();

            if (itemID == "1000" || itemID == "1001")
            {
                if (itemID == "1000")
                    return;
                else
                {
                    string currentPRGroupKey = (from gg in this.GroupGroupList
                                                where gg.ChGroup == this._onProcess
                                                select gg.PrGroup).FirstOrDefault();

                    if (string.IsNullOrEmpty(currentPRGroupKey))
                    {
                        currentPRGroupKey = (from og in this.ObjectGroupList
                                             where og.GroupId == this._onProcess
                                             select og.Objectid).FirstOrDefault();

                        if (!string.IsNullOrEmpty(currentPRGroupKey))
                        {
                            this.PopulateMainMenu(string.Empty, currentPRGroupKey, this.RegisteredUser.UserType);
                            this._onProcess = currentPRGroupKey;
                        }
                    }
                    else
                    {
                        this.PopulateMenu(currentPRGroupKey);
                        this._onProcess = currentPRGroupKey;
                    }
                }
            }
            else
            {
                ButtonInfo currentButtonInfo = this._menuButtonInfoList.FirstOrDefault(m => m.ID.ToString() == itemID);
                int currentType = currentButtonInfo == null ? 0 : currentButtonInfo.Type;
                string currentKey = currentButtonInfo == null ? string.Empty : currentButtonInfo.Key;

                if (currentType == 2)
                {
                    Dictionary<string, string> navigationParams = new Dictionary<string,string>();

                    // TODO: go to other page I think...
                    if (currentKey == "PTBH")
                    {
                        navigationParams.Add("Customerkey", "0");
                        navigationParams.Add("salespkey", "0");
                    }

                    if (currentKey == "DH")
                        navigationParams.Add("optionOrder", "01");

                    if (currentKey == "DHPRE")
                        navigationParams.Add("optionOrder", "11");

                    this._onProcess = currentKey;
                }
                else
                {
                    this._onProcess = currentKey;
                    this.PopulateMenu(currentKey);
                }
            }
        }

        private void PopulateSidebar(List<SqlGroup> groupList)
        {
            foreach (SqlGroup group in groupList)
            {
                ButtonInfo menuButtonInfo = new ButtonInfo
                {
                    Key = group.Groupkey,
                    Text = group.Groupdes
                };

                Button menu = this.CreateButton(menuButtonInfo, true);

                this._menuBar.Children.Add(menu);
            }
        }

        private void PopulateMainMenu(string key, string objectId, string userType)
        {
            int i = 0;

            /*
             * public String getAppStatus(Context paramContext) {
             *      return new cSQLCmd().GetStringSql("Select case when AppStatus is null then 0 else AppStatus end as AppStatus from ARSALESPTYPE", paramContext);
             * }
             */
            string appStatus = this.RegisteredUser.AppStatus;
            if (string.IsNullOrEmpty(appStatus))
                appStatus = "0";

            List<Button> menuButtonList = new List<Button>();

            List<SqlGroup> groupList = new List<SqlGroup>();
            List<string> groupIDList = new List<string>();

            List<SqlMenu> menuList = new List<SqlMenu>();
            List<string> menuIDList = new List<string>();

            if (objectId == "ALL")
            {
                groupList = this.GroupList.Where(g => g.UseType == this.RegisteredUser.UserType).ToList();
            }
            else if (appStatus == "0")
            {
                groupIDList = (from og in this.ObjectGroupList
                               where og.Objectid == objectId
                               select og.GroupId).ToList();

                if (groupIDList.Count > 0)
                {
                    groupList = (from g in this.GroupList
                                 where groupIDList.Where(id => id == g.Groupkey).Any()
                                 orderby g.Sort
                                 select g).ToList();
                }
            }
            else
            {
                groupIDList = (from og in this.ObjectGroupList
                               where og.Objectid == objectId
                               select og.GroupId).ToList();

                if (groupIDList.Count > 0)
                {
                    groupList = (from g in this.GroupList
                                 where groupIDList.Where(id => id == g.Groupkey).Any() && (g.AppStatus == 0 || g.AppStatus.ToString() == appStatus)
                                 orderby g.Sort
                                 select g).ToList();
                }
            }

            // create and add button
            if (groupList.Count > 0)
            {
                foreach (SqlGroup group in groupList)
                {
                    // TODO: Adds Icon later...
                    ButtonInfo menuButtonInfo = new ButtonInfo
                    {
                        ID = i,
                        Order = i + 1,
                        Type = 1,
                        IsEnd = true,
                        Key = group.Groupkey,
                        Process = group.Groupkey,
                        Text = group.Groupdes
                    };

                    this._menuButtonInfoList.Add(menuButtonInfo);

                    Button menuButton = this.CreateButton(menuButtonInfo, true);

                    menuButtonList.Add(menuButton);

                    ++i;
                }
            }

            if (appStatus == "0")
            {
                menuIDList = (from om in this.ObjectMenuList
                              where om.Objectid == objectId
                              select om.Menuid).ToList();

                if (menuIDList.Count > 0)
                {
                    menuList = (from m in this.MenuList
                                where menuIDList.Where(id => id == m.Type).Any()
                                select m).ToList();
                }
            }
            else
            {
                menuIDList = (from om in this.ObjectMenuList
                              where om.Objectid == objectId
                              select om.Menuid).ToList();

                if (menuIDList.Count > 0)
                {
                    menuList = (from m in this.MenuList
                                where menuIDList.Where(id => id == m.Type).Any() && (m.AppStatus == 0 || m.AppStatus.ToString() == appStatus)
                                select m).ToList();
                }
            }

            if (menuList.Count > 0)
            {
                foreach (SqlMenu menu in menuList)
                {
                    // TODO: Adds Icon later...
                    ButtonInfo menuButtonInfo = new ButtonInfo
                    {
                        ID = i,
                        Order = i + 1,
                        Type = 2,
                        Key = menu.Type,
                        Process = "Khakha",
                        Text = menu.Description
                    };

                    this._menuButtonInfoList.Add(menuButtonInfo);

                    Button menuButton = this.CreateButton(menuButtonInfo, true);

                    menuButtonList.Add(menuButton);

                    ++i;
                }
            }

            if (i == 0)
            {
                ButtonInfo additionalMenuButtonInfo = new ButtonInfo
                {
                    ID = i,
                    Order = i + 1,
                    Type = 2,
                    Key = "ST",
                    Process = "Khakha",
                    Image = this.GetButtonIconUrl(Localization.AppResources.COMMON_ACTION_SETTING),
                    Text = Localization.AppResources.COMMON_ACTION_SETTING
                };

                this._menuButtonInfoList.Add(additionalMenuButtonInfo);

                Button additionalMenuButton = this.CreateButton(additionalMenuButtonInfo, true);

                menuButtonList.Add(additionalMenuButton);

                ++i;

                if (this.RegisteredUser.UserType == "DSR")
                {
                    additionalMenuButtonInfo = new ButtonInfo
                    {
                        ID = i,
                        Order = i + 1,
                        Type = 2,
                        Key = "DSRDBDL",
                        Process = "Khakha",
                        Image = this.GetButtonIconUrl(Localization.AppResources.COMMON_ACTION_DATASYNC),
                        Text = Localization.AppResources.COMMON_ACTION_SETTING
                    };

                    this._menuButtonInfoList.Add(additionalMenuButtonInfo);

                    additionalMenuButton = this.CreateButton(additionalMenuButtonInfo, true);

                    menuButtonList.Add(additionalMenuButton);

                    ++i;
                }

                if (this.RegisteredUser.UserType == "SS")
                {
                    additionalMenuButtonInfo = new ButtonInfo
                    {
                        ID = i,
                        Order = i + 1,
                        Type = 2,
                        Key = "SSDBDL",
                        Process = "Khakha",
                        Image = this.GetButtonIconUrl(Localization.AppResources.COMMON_ACTION_DATASYNC),
                        Text = Localization.AppResources.COMMON_ACTION_SETTING
                    };

                    additionalMenuButton = this.CreateButton(additionalMenuButtonInfo, true);

                    menuButtonList.Add(additionalMenuButton);

                    ++i;
                }
            }

            // add menu button to side-bar
            foreach (Button menuButton in menuButtonList)
            {
                this._menuBar.Children.Add(menuButton);
            }

            // TODO: add exit button
        }

        private void PopulateMenu(string key)
        {
            string userType = this.RegisteredUser.UserType;
            string appStatus = this.RegisteredUser.AppStatus;
            if (string.IsNullOrEmpty(appStatus))
                appStatus = "0";

            int i = 0;
            List<Button> menuButtonList = new List<Button>();

            if (appStatus == "0")
            {
                var menus = from m in this.MenuList
                            from gm in this.GroupMenuList
                            where m.Type == gm.MenuKey && gm.GroupKey == key && gm.Show == 1 && m.usertype == userType
                            orderby gm.Sort
                            select new
                            {
                                m.Type,
                                m.Description,
                                m.imge,
                                gm.NextProcess,
                                gm.isEnd
                            };

                if (menus.Any())
                {
                    foreach (var menu in menus)
                    {
                        // TODO: Adds Icon later...
                        ButtonInfo menuButtonInfo = new ButtonInfo
                        {
                            ID = i,
                            Order = i + 1,
                            Type = 2,
                            IsEnd = true,
                            Key = menu.Type,
                            Process = key,
                            //Image = menu.imge,
                            Text = menu.Description
                        };

                        this._menuButtonInfoList.Add(menuButtonInfo);

                        Button menuButton = this.CreateButton(menuButtonInfo, true);

                        menuButtonList.Add(menuButton);

                        ++i;
                    }
                }
            }
            else
            {
                var menus = from m in this.MenuList
                            from gm in this.GroupMenuList
                            where m.Type == gm.MenuKey && gm.GroupKey == key && gm.Sort == 1 && m.usertype == userType && (m.AppStatus == 0 || m.AppStatus.ToString() == appStatus)
                            orderby gm.Sort
                            select new
                            {
                                m.Type,
                                m.Description,
                                m.imge,
                                gm.NextProcess,
                                gm.isEnd
                            };

                if (menus.Any())
                {
                    foreach (var menu in menus)
                    {
                        // TODO: Adds Icon later...
                        ButtonInfo menuButtonInfo = new ButtonInfo
                        {
                            ID = i,
                            Order = i + 1,
                            Type = 2,
                            IsEnd = true,
                            Key = menu.Type,
                            Process = key,
                            //Image = menu.imge,
                            Text = menu.Description
                        };

                        this._menuButtonInfoList.Add(menuButtonInfo);

                        Button menuButton = this.CreateButton(menuButtonInfo, true);

                        menuButtonList.Add(menuButton);

                        ++i;
                    }
                }
            }

            if (appStatus == "0")
            {
                var menus = from g in this.GroupList
                            from gg in this.GroupGroupList
                            where g.Groupkey == gg.ChGroup && gg.PrGroup == key && g.UseType == userType
                            orderby g.Sort
                            select new
                            {
                                Type = g.Groupkey,
                                Description = g.Groupdes,
                                g.Image,
                                NextProcess = "0",
                                IsEnd = true
                            };

                if (menus.Any())
                {
                    foreach (var menu in menus)
                    {
                        // TODO: Adds Icon later...
                        ButtonInfo menuButtonInfo = new ButtonInfo
                        {
                            ID = i,
                            Order = i + 1,
                            Type = 1,
                            IsEnd = true,
                            Key = menu.Type,
                            Process = key,
                            //Image = menu.imge,
                            Text = menu.Description
                        };

                        this._menuButtonInfoList.Add(menuButtonInfo);

                        Button menuButton = this.CreateButton(menuButtonInfo, true);

                        menuButtonList.Add(menuButton);

                        ++i;
                    }
                }
            }
            else
            {
                var menus = from g in this.GroupList
                            from gg in this.GroupGroupList
                            where g.Groupkey == gg.ChGroup && gg.PrGroup == key && g.UseType == userType && (g.AppStatus == 0 || g.AppStatus.ToString() == appStatus)
                            orderby g.Sort
                            select new
                            {
                                Type = g.Groupkey,
                                Description = g.Groupdes,
                                g.Image,
                                NextProcess = "0",
                                IsEnd = true
                            };

                if (menus.Any())
                {
                    foreach (var menu in menus)
                    {
                        // TODO: Adds Icon later...
                        ButtonInfo menuButtonInfo = new ButtonInfo
                        {
                            ID = i,
                            Order = i + 1,
                            Type = 1,
                            IsEnd = true,
                            Key = menu.Type,
                            Process = key,
                            //Image = menu.imge,
                            Text = menu.Description
                        };

                        this._menuButtonInfoList.Add(menuButtonInfo);

                        Button menuButton = this.CreateButton(menuButtonInfo, true);

                        menuButtonList.Add(menuButton);

                        ++i;
                    }
                }
            }

            this._menuBar.Children.Clear();
            foreach (Button menu in menuButtonList)
            {
                this._menuBar.Children.Add(menu);
            }
        }

        private Button CreateButton(ButtonInfo info, bool isSidebarMenu = false)
        {
            StackPanel buttonStackPanel = new StackPanel();

            TextBlock buttonText = new TextBlock
            {
                Text = info.Text,
                TextWrapping = TextWrapping.Wrap,
                Foreground = new SolidColorBrush(Colors.Black),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            if (!string.IsNullOrEmpty(info.Image))
            {
                Image buttonIcon = new Image()
                {
                    Source = new BitmapImage(new Uri(info.Image, UriKind.Relative)),
                    Stretch = Stretch.None
                };

                buttonStackPanel.Children.Add(buttonIcon);
            }

            buttonStackPanel.Children.Add(buttonText);

            Button button = new Button
            {
                Tag = info.Key,
                Content = buttonStackPanel,
                Style = (Style)Application.Current.Resources["TiltableButtonStyle"]
            };

            if (isSidebarMenu)
                button.Click += SidebarMenuOnClick;
            else
                button.Click += ActionButtonOnClick;

            return button;
        }

        private class ButtonInfo
        {
            public int ID { get; set; }

            public int Order { get; set; }

            public int Type { get; set; }

            public bool IsEnd { get; set; }

            public string Key { get; set; }

            public string Text { get; set; }

            public string Image { get; set; }

            public string Process { get; set; }
        }
    }
}
